#include <gtest/gtest.h>

void abort_func() { abort(); }

void crash_func(const int a) {
    if (a == 0) {
        fprintf(stderr, "hello\n");
        int* ptr = nullptr;
        *ptr = 0;
    }
    exit(50);
}

TEST(DeathTest, Crash) { ASSERT_DEATH(crash_func(0), "world"); }

TEST(DeathTest, Abort) {
    EXPECT_EXIT(abort_func(), testing::KilledBySignal(SIGABRT), ".*");
}

TEST(DeathTest, CrashCode) {
    EXPECT_EXIT(crash_func(0), testing::KilledBySignal(SIGSEGV), ".*");
}

TEST(DeathTest, Normal) {
    EXPECT_EXIT(crash_func(1), testing::ExitedWithCode(50), ".*");
}